///////////////////////////////查询基本情况的方法群////////////////////////////////////////

var yjdc3jbxxQueryDlg = null;

var yjdc3jbxxQueryByTybhDlg = null;

var clickName;

function initYjdc3jbxxQueryDlg(){
	if(yjdc3jbxxQueryDlg)
		return;
	var yjdc3jbxxQueryHtml = '<div style="width:340px;height:200px;font-size:11px;font-family:微软雅黑;position:absolute;left:15px;top:40px;">'+
												'<div id="yjdc3jbxxQueryConditionBar" style="position:absolute;left:0px;top:0px;width:340px;height:40px;">'+
												'<label>时间范围：</label><input id="yjdc3jbxxTimeInputForm" type="text" style="width:120px;height:18px;" class="Wdate" onfocus="WdatePicker({startDate: \'00:00:00\',dateFmt:\'yyyy-MM-dd HH:mm:ss\',alwaysUseStartDate:true})"/> '+
												' — <input id="yjdc3jbxxTimeInputTo" style="width:120px;height:18px;" type="text" class="Wdate" onfocus="WdatePicker({startDate:\'00:00:00\',dateFmt:\'yyyy-MM-dd HH:mm:ss\',alwaysUseStartDate:true})"/>'+
												'<br/>'+
												'<label>灾害名称：</label><input id="yjdc3jbxxNameInputTo" style="width:150px;height:15px;"/>'+
												'<input id="yjdc3jbxxQueryButton" type="button" value="确定" />'+
												'</div>'+
												'<div id="queryYjdc3JbxxResultContent" style="width:330px;height:135px;border:1px solid #ABADB3;position:absolute;left:2px;top:55px;overflow-y:auto;overflow-x:hidden;">'+
												'<table id="queryYjdc3JbxxResultTable" style="font-size:11px;width:330px;border-collapse: collapse;">'+
													'<tr>'+
														'<td class="queryTd">序号</td><td class="queryTd">灾害名称</td><td class="queryTd">灾害编号</td>'+
													'</tr>'+
												'</table>'+
											'</div>'+
											'</div>';
	yjdc3jbxxQueryDlg = $.dialog({
		title: '基本情况查询',
		content: yjdc3jbxxQueryHtml,
		dlgDivId: "yjdc3jbxxQueryId",
		resize: false,
		max: false,
		left:"250px",
		top:'100px',
		width:'340px',
		height:'200px',
		min:yjdc3jbxxQueryDlgMinFunc,
		init:function(){
			$("#yjdc3jbxxQueryButton").click(queryYjdc3jbxxFunction);
		},
		close:yjdc3jbxxQueryDlgCloseFunc
	});
}

function yjdc3jbxxQueryDlgMinFunc(){
	minDlgByAnimate(yjdc3jbxxQueryDlg);
}

function yjdc3jbxxQueryDlgCloseFunc(){
	yjdc3jbxxQueryDlg = null;
}

//查询按钮的点击事件
function queryYjdc3jbxxFunction(){
	var startTime = $("#yjdc3jbxxTimeInputForm").val();
	var endTime = $("#yjdc3jbxxTimeInputTo").val();
	var name = $("#yjdc3jbxxNameInputTo").val();
	var obj = {startTime:startTime,endTime:endTime,name:name};
	var url = "queryYjdc3jbxxBenji.shtml";
	$.post(url,obj,queryYjdc3jbxxBenjiCallback);
}

function queryYjdc3jbxxBenjiCallback(res){
	$(".yjdc3ResultTr").remove();
	res = eval("("+res+")");
	if(res.length>0){
		for(var i = 0;i<res.length;i++){
			var tybh = res[i][0];
			var name = res[i][1];
			var biaoshi = res[i][2];
			var type = getOperTypeZhdByCode(biaoshi);
			var resStr =  '<tr class="yjdc3ResultTr">'+
			'<td class="queryTd">'+(i+1)+'</td><td class="queryClickTd" id="'+i+'" style="cursor:pointer;">'+name+'</td><td class="queryTd">'+tybh+'</td><td class="queryTd">'+type+'</td>'+
			'</tr>';
			$("#queryYjdc3JbxxResultTable").append(resStr);
			$(".queryClickTd").click(function(evt){
				var index = evt.currentTarget.id;
				queryYJDC01ByTybh(res[index][0],res[index][1],res[index][2]);
			});
		}
	}else{
		alert("没有查询到任何信息!");
	}
}


//通过统一编号去查询此统一编号下的信息
function queryYJDC01ByTybh(tybh,name,biaoshi){
	clickName = name;
	var url = "queryYjdc3jbxxByTybh.shtml";
	var startTime = $("#yjdc3jbxxTimeInputForm").val();
	var endTime = $("#yjdc3jbxxTimeInputTo").val();
	var data = {
			startTime:startTime,
			endTime:endTime,
			tybh:tybh,
			biaoshi:biaoshi
	};
	$.post(url,data,yjdc01ByTybhCallback);
}

//通过统一编号去查询的回调
function yjdc01ByTybhCallback(res){
	res = eval("("+res+")");
	//将查询到的结果，通过对话框展示出来
	initYjdc3jbxxQueryByTybhDlg(res);
}


////////////////////////////////////////////////////////////////////////////////////////
//展示结果的对话框
function initYjdc3jbxxQueryByTybhDlg(res){
	if(yjdc3jbxxQueryByTybhDlg){//如果存在
		yjdc3jbxxQueryByTybhDlg.close();
		yjdc3jbxxQueryByTybhDlg = null;
	}
	var dlgStr = '<div id="fanzaoDiv" style="width:490px;height:270px;font-size:11px;font-family:微软雅黑;overflow-y:auto;overflow-x:hidden;">'+
		'<label style="color: red;">请您选择应急调查的时间:</label><select style="width:150px;" id="chooseTime"></select>'+
		'<form id="yjdclrFormEdit" method="post" enctype="multipart/form-data" >'+
			'<table style="font-size:11px;width:470px;border-collapse: collapse;" >'+
			'<tr style="display:none">'+
				'<td><input id="yjdcdTYBH"  type="text" name ="yjdc01.yjdc01000" style="width:250px;"></td>'+
				'<td><input id="yjdcdType"  type="text" name ="yjdc01.jbqk0102" style="width:250px;"></td>'+
				'<td><input id="yjdcdID"  type="text" name ="yjdc01.id" style="width:250px;"></td>'+
				'<td><input id="yjdcdQuanmao"  type="text" name ="yjdc01.yjdc01300" style="width:250px;"></td>'+
				'<td><input id="yjdcdLianjie1"  type="text" name ="yjdc01.yjdc01310" style="width:250px;"></td>'+
				'<td><input id="yjdcdLianjie2"  type="text" name ="yjdc01.yjdc01320" style="width:250px;"></td>'+
			'</tr>'+
				'<tr>'+
					'<td><label>应急调查点:</label></td><td colspan="3"><input id="yjdcdNameInputEdit"  type="text" style="width:250px;" onkeyup="getYJDCDByKeyword();">*</td>'+
				'</tr>'+
				'<tr>'+
					'<td><label>经度:</label></td><td><input type="text" id="yjdcdjingduEdit" name="yjdc01.yjdc01350" style="width:110px;"/></td><td><label>纬度:</label></td><td><input id="yjdcdweiduEdit" name="yjdc01.yjdc01360" type="text" style="width:110px;"/></td>'+
				'</tr>'+
				'<tr>'+
					'<td><label>高度:</label></td><td><input type="text" id="yjdcdgaoduEdit" name="yjdc01.yjdc01370" style="width:110px;"/></td>'+
					'<td><label>规模等级:</label></td><td><select  name="yjdc01.yjdc01240" id="gmdjEdit" style="width:110px;">'+
					'<option selected="selected" value="4">小型</option>'+
					'<option value="3">中型</option>'+
					'<option value="2">大型</option>'+
					'<option value="1">特大型</option>'+
					'</select></td>'+
				'</tr>'+
				'<tr>'+
					'<td><label>地理位置:</label></td><td colspan="3"><input type="text" name="yjdc01.yjdc01030" id="yjdcdDlwzEdit" style="width:300px;"></td>'+
				'</tr>'+
				'<tr>'+
					'<td><label>调查时间:</label></td><td><input type="text" name="yjdc01.yjdc01270" id="dcsjInputEdit" style="width:110px;" >*</td><td><label>变形初始时间:</label></td><td><input id="bxcssjEdit" name="yjdc01.yjdc01010" type="text" style="width:110px;" class="Wdate" onfocus="WdatePicker({startDate:\' 00:00:00\',dateFmt:\'yyyy-MM-dd HH:mm:ss\',alwaysUseStartDate:true})"></td>'+
				'</tr>'+
				'<tr>'+
					'<td><label>前缘高程:</label></td><td><input type="text" id="qygcEdit" name="yjdc01.yjdc01040" style="width:110px;"/>m</td><td><label>后缘高程:</label></td><td><input id="hygcEdit" name="yjdc01.yjdc01050" type="text" style="width:110px;"/>m</td>'+
				'</tr>'+
				'<tr>'+
					'<td><label>地层岩性:</label></td><td><input type="text" name="yjdc01.yjdc01060" id="dcyxEdit" style="width:110px;"/></td><td><label>地质构造:</label></td><td><input id="dzgzEdit" name="yjdc01.yjdc01070" type="text" style="width:110px;"/></td>'+
				'</tr>'+
				'<tr>'+
					'<td><label>多年平均降雨量:</label></td><td><input type="text" name="yjdc01.yjdc01080" id="dnpjjylEdit" style="width:100px;"/>mm</td><td><label>长:</label></td><td><input id="changEdit" type="text" name="yjdc01.yjdc01090" style="width:110px;"/>m</td>'+
				'</tr>'+
				'<tr>'+
					'<td><label>宽:</label></td><td><input id="kuangEdit"  name="yjdc01.yjdc01100" type="text" style="width:110px;"/>m</td><td><label>高:</label></td><td><input id="gaoEdit"  name="yjdc01.yjdc01110" type="text" style="width:110px;"/>m</td>'+
				'</tr>'+
				'<tr>'+
					'<td><label>面积:</label></td><td><input id="mianjiEdit" type="text" name="yjdc01.yjdc01120" style="width:110px;"/>㎡</td><td><label>体积:</label></td><td><input id="tijiEdit" type="text" name="yjdc01.yjdc01130" style="width:110px;"/>m³</td>'+
				'</tr>'+
				'<tr>'+
					'<td><label>人类工程诱发因素:</label></td><td colspan="3"><input type="checkbox" id="rggcyfys1" name="rggcyfysEdit" value="1"/>修路切坡<input type="checkbox" id="rggcyfys2" name="rggcyfysEdit" value="2">建房切坡<input type="checkbox" id="rggcyfys3" name="rggcyfysEdit" value="3"/>采矿<input type="checkbox" id="rggcyfys4" name="rggcyfysEdit" value="4"/>矿山疏排地下水</td>'+
				'</tr>'+
				'<tr>'+
					'<td><label>坡体结构:</label></td><td colspan="3"><select style="width:300px;" id="ptjgEdit" name="yjdc01.yjdc01072">'+
						'<option value="" selected="selected">请选择</option>'+
						'<option value="1">顺向坡</option>'+
						'<option value="2">斜顺向坡</option>'+
						'<option value="3">横向坡</option>'+
						'<option value="4">斜反向坡</option>'+
						'<option value="5">反向坡</option>'+
					'</select></td>'+
				'</tr>'+
				'<tr>'+
					'<td><label>目前稳定状态:</label></td><td><select style="width:110px;" id="mqwdztEdit" name="yjdc01.yjdc01150">'+
						'<option  selected="selected"  value="">请选择</option>'+
					'<option value="A">稳定</option>'+
					'<option value="B">基本稳定</option>'+
					'<option value="C">不稳定</option>'+
					'</select></td><td><label>今后变化趋势:</label></td><td colspan="3"><select style="width:110px;" id="jhbhqsEdit" name="yjdc01.yjdc01160">'+
					'<option  selected="selected"  value="">请选择</option>'+
					'<option value="A">稳定</option>'+
					'<option value="B">基本稳定</option>'+
					'<option value="C">不稳定</option>'+
					'</select></td>'+
				'</tr>'+
				'<tr>'+
					'<td><label>直接经济损失:</label></td><td><input type="text" id="zjjjssEdit"  name="yjdc01.yjdc01170" style="width:90px;"/>万元</td><td><label>威胁财产:</label></td><td><input type="text" id="wxccEdit" style="width:90px;" name="yjdc01.yjdc01200"/>万元</td>'+
				'</tr>'+
				'<tr>'+
					'<td><label>死亡人数:</label></td><td><input type="text" style="width:110px;" id="swrsEdit" name="yjdc01.yjdc01180"/>人</td><td><label>威胁人口:</label></td><td><input id="wxrkEdit" type="text" style="width:110px;"  name="yjdc01.yjdc01190"/>人</td>'+
				'</tr>'+
				'<tr>'+
					'<td><label>失踪人数:</label></td><td><input id="szrsEdit" type="text" style="width:110px;" name="yjdc01.yjdc01181"/>人</td><td><label>受伤人口:</label></td><td><input id="ssrkEdit" type="text" style="width:110px;"  name="yjdc01.yjdc01182"/>人</td>'+
				'</tr>'+
				'<tr>'+
					'<td>监测建议:</td><td colspan="3"><textarea rows="3" id="jcjyEdit" style="width:300px;" name="yjdc01.yjdc01210"></textarea></td>'+
				'</tr>'+
				'<tr>'+
					'<td>防治建议:</td><td colspan="3"><textarea rows="3" id="fzjyEdit" style="width:300px;" name="yjdc01.yjdc01220"></textarea></td>'+
				'</tr>'+
				'<tr>'+
					'<td>灾情等级:</td><td colspan="3"><select style="width:300px;" id="zqdjEdit"  name="yjdc01.yjdc01230">'+
						'<option  selected="selected"  value="">请选择</option>'+
					'<option value="4">小型</option>'+
					'<option value="3">中型</option>'+
					'<option value="2">大型</option>'+
					'<option value="1">特大型</option>'+
					'</select></td>'+
				'</tr>'+
				'<tr>'+
					'<td><label>调查人:</label></td><td><input type="text" id="dcrEdit" style="width:110px;" name="yjdc01.yjdc01250"/></td><td><label>调查单位:</label></td><td><input type="text" id="dcdwEdit" style="width:110px;" name="yjdc01.yjdc01260"/></td>'+
				'</tr>'+
				'<tr>'+
					'<td><label>现场处理意见:</label></td><td colspan="3"><input type="checkbox" id="xcclyj1" name="xcclyjEdit" value="1"/>设置路牌<input type="checkbox" id="xcclyj2" name="xcclyjEdit" value="2">紧急搬迁<input type="checkbox" id="xcclyj3" name="xcclyjEdit" value="3"/>应急监测</td>'+
				'</tr>'+
			'</table>'+
		'</form>'+
			'<input type="button" value="提交" id="editInsertButton" style="margin-left:150px;margin-right:100px;"/><input type="button" value="重置" onclick = ""/>'+
			'</div>';
	yjdc3jbxxQueryByTybhDlg = $.dialog({
		title: '调查基本信息编辑',
		content: dlgStr,
		dlgDivId: "yjdc3jbxxQueryId",
		resize: false,
		max: false,
		left:"250px",
		top:'100px',
		width:'490px',
		height:'270px',
		min:false,
		init:function(){
			$("#fanzaoDiv td").css("border","1px solid #D8DBE0");
			//初始化完毕，加载时间选择列表
			var optionStr = '<option selected="selected" value="">请选择调查时间</option>';
			for(var i = 0;i<res.length;i++){
				var time = res[i].yjdc01270;
				var year = Number(time.year)+1900;
				var month = (Number(time.month)+1)<10?"0"+(Number(time.month)+1):(Number(time.month)+1);
				var day = Number(time.date<10)?"0"+time.date:time.date;
				var hours = Number(time.hours<10)?"0"+time.hours:time.hours;
				var minutes = Number(time.minutes<10)?"0"+time.minutes:time.minutes;
				var seconds = Number(time.seconds<10)?"0"+time.seconds:time.seconds;
				var timeStr  = year+"-"+month+"-"+day+" "+hours+":"+minutes+":"+seconds;
				optionStr = optionStr + '<option value="'+i+'">'+timeStr+'</option>';
			}
			$("#chooseTime").html("");
			$("#chooseTime").append(optionStr);
			$("#chooseTime").change(function(){
				var index = $("#chooseTime").val();
				if(index=="")
					return;
				giveValueToEdit(res[index]);
			})
			$("#editInsertButton").click(editInsertClickFunction);
		},
		close:function(){
			yjdc3jbxxQueryByTybhDlg = null;
		}	
	});
}

function giveValueToEdit(obj){
	//全貌名称
	$("#yjdcdQuanmao").attr("value",obj.yjdc01300);
	//链接1
	$("#yjdcdLianjie1").attr("value",obj.yjdc01310);
	//链接2
	$("#yjdcdLianjie2").attr("value",obj.yjdc01320);
	//统一编号
	$("#yjdcdTYBH").attr("value",obj.yjdc01000);
	//id
	$("#yjdcdID").attr("value",obj.id);
	//灾害点标志
	$("#yjdcdType").attr("value",obj.jbqk0102);
	//名称
	$("#yjdcdNameInputEdit").attr("value",clickName).attr("readOnly","readOnly");
	//经度
	$("#yjdcdjingduEdit").attr("value",obj.yjdc01350).attr("readOnly","readOnly");
	//纬度
	$("#yjdcdweiduEdit").attr("value",obj.yjdc01360).attr("readOnly","readOnly");
	//高度
	$("#yjdcdgaoduEdit").attr("value",obj.yjdc01370).attr("readOnly","readOnly");
	//
	var time = obj.yjdc01270;
	var year = Number(time.year)+1900;
	var month = (Number(time.month)+1)<10?"0"+(Number(time.month)+1):(Number(time.month)+1);
	var day = Number(time.date<10)?"0"+time.date:time.date;
	var hours = Number(time.hours<10)?"0"+time.hours:time.hours;
	var minutes = Number(time.minutes<10)?"0"+time.minutes:time.minutes;
	var seconds = Number(time.seconds<10)?"0"+time.seconds:time.seconds;
	var timeStr  = year+"-"+month+"-"+day+" "+hours+":"+minutes+":"+seconds;
	//调查时间
	$("#dcsjInputEdit").attr("value",timeStr).attr("readOnly","readOnly");
	//规模等级
	$("#gmdjEdit").attr("value",obj.yjdc01240);
	//地理位置
	$("#yjdcdDlwzEdit").attr("value",obj.yjdc01030);
	//变形初始时间
	//
	var bxTime = obj.yjdc01010;
	bxtimeStr = "";
	if(bxTime!=null){
		var bxyear = Number(bxTime.year)+1900;
		var bxmonth = (Number(bxTime.month)+1)<10?"0"+(Number(bxTime.month)+1):(Number(bxTime.month)+1);
		var bxday = Number(bxTime.date)<10?"0"+bxTime.date:bxTime.date;
		var bxhours = Number(bxTime.hours)<10?"0"+bxTime.hours:bxTime.hours;
		var bxminutes = Number(bxTime.minutes)<10?"0"+bxTime.minutes:bxTime.minutes;
		var bxseconds = Number(bxTime.seconds)<10?"0"+bxTime.seconds:bxTime.seconds;
		bxtimeStr  = bxyear+"-"+bxmonth+"-"+bxday+" "+bxhours+":"+bxminutes+":"+bxseconds;
	}
    $("#bxcssjEdit").attr("value",bxtimeStr);
    //前缘高程
    $("#qygcEdit").attr("value",obj.yjdc01040==0?"":obj.yjdc01040);
    //后缘高程
    $("#hygcEdit").attr("value",obj.yjdc01050==0?"":obj.yjdc01050);
    //地层岩性
    $("#dcyxEdit").attr("value",obj.yjdc01060);
    //地质构造
    $("#dzgzEdit").attr("value",obj.yjdc01070);
    //多年平均降雨量
    $("#dnpjjylEdit").attr("value",obj.yjdc01080==0?"":obj.yjdc01080);
    //长
    $("#changEdit").attr("value",obj.yjdc01090==0?"":obj.yjdc01090);
    //宽
    $("#kuangEdit").attr("value",obj.yjdc01100==0?"":obj.yjdc01100);
    //高
    $("#gaoEdit").attr("value",obj.yjdc01110==0?"":obj.yjdc01110);
    //面积
    $("#mianjiEdit").attr("value",obj.yjdc01120==0?"":obj.yjdc01120);
    //体积
    $("#tijiEdit").attr("value",obj.yjdc01130==0?"":obj.yjdc01130);
    //人类工程诱发因素checkbox
    var rggcyfysArray = obj.yjdc01140.split(",");
    for(var i = 0;i<rggcyfysArray.length;i++){
    	$("#rggcyfys"+rggcyfysArray[i]).attr({checked:true});
    }
    //坡体结构
    $("#ptjgEdit").attr("value",obj.yjdc01072);
    //目前稳定状态
    $("#mqwdztEdit").attr("value",obj.yjdc01150);
    //今后变化趋势
    $("#jhbhqsEdit").attr("value",obj.yjdc01160);
    //直接经济损失
    $("#zjjjssEdit").attr("value",obj.yjdc01170==0?"":obj.yjdc01170);
    //威胁财产
    $("#wxccEdit").attr("value",obj.yjdc01200==0?"":obj.yjdc01200);
    //死亡人数
    $("#swrsEdit").attr("value",obj.yjdc01180==0?"":obj.yjdc01180);
    //失踪人数
    $("#szrsEdit").attr("value",obj.yjdc01181==0?"":obj.yjdc01181);
    //受伤人口
    $("#ssrkEdit").attr("value",obj.yjdc01182==0?"":obj.yjdc01182);
    //威胁人口
    $("#wxrkEdit").attr("value",obj.yjdc01190==0?"":obj.yjdc01190);
    //监测建议
    $("#jcjyEdit").attr("value",obj.yjdc01210);
    //防治建议
    $("#fzjyEdit").attr("value",obj.yjdc01220);
    //灾情等级
    $("#zqdjEdit").attr("value",obj.yjdc01230);
    //调查人
    $("#dcrEdit").attr("value",obj.yjdc01250);
    //调查单位
    $("#dcdwEdit").attr("value",obj.yjdc01260);
    //现场处理意见checkbox
    var xcclyjArray = obj.yjdc01330.split(",");
    for(var i = 0;i<xcclyjArray.length;i++){
    	$("#xcclyj"+xcclyjArray[i]).attr({checked:true});
    }
}

//点击提交之后，更新数据库
function editInsertClickFunction(){
	var yjdc01140Array = $("input[name=rggcyfysEdit]:checked");
	var yjdc01140 = "";
	if(yjdc01140Array.length>0){
		for(var i = 0;i<yjdc01140Array.length-1;i++){
			yjdc01140 = yjdc01140 + yjdc01140Array[i].value+",";
		}
		yjdc01140 = yjdc01140 + yjdc01140Array[yjdc01140Array.length-1].value;
	}
	var yjdc01330Array = $("input[name=xcclyjEdit]:checked");
	var yjdc01330 = "";
	if(yjdc01330Array.length>0){
		for(var j = 0;j<yjdc01330Array.length-1;j++){
			yjdc01330 = yjdc01330 + yjdc01330Array[j].value +",";
		}
		yjdc01330 = yjdc01330 + yjdc01330Array[yjdc01330Array.length-1].value;
	}
	var yjdcdType = $("#yjdcdType").attr("value");
	$("#yjdclrFormEdit").attr("action","jbxxUpdateForYjdc3.shtml?jbqk0102="+yjdcdType+"&yjdc01140="+yjdc01140+"&yjdc01330="+yjdc01330);
	$("#yjdclrFormEdit").submit(function () {
        // 提交表单
        $(this).ajaxSubmit();
        // 为了防止普通浏览器进行表单提交和产生页面导航（防止页面刷新？）返回false
        return false;
    });
    $("#yjdclrFormEdit").ajaxSubmit(function (res) {
    	if(res.length>4){
   		 	//内容的转化（内容有标签时），防止谷歌对jquery的返回对象不同
     		var hiddenDiv = $("<div>");
     		hiddenDiv.html(res);
     		res = hiddenDiv.text();
   		}
    	if(res=="true"){
    		alert("插入成功!");
    		//关闭对话框
    		yjdc3jbxxQueryByTybhDlg.close();
    	}else{
    		alert("插入失败！");
    	}
    });
}

